<?php

namespace common\models\wechat;

use Yii;

/**
 * This is the model class for table "wechat_accounts".
 *
 * @property string $id
 * @property string $token
 * @property string $access_token
 * @property integer $level
 * @property string $name
 * @property string $account
 * @property string $original
 * @property string $signature
 * @property string $country
 * @property string $province
 * @property string $city
 * @property string $username
 * @property string $password
 * @property string $lastupdate
 * @property string $key
 * @property string $secret
 * @property string $styleid
 * @property string $encodingaeskey
 * @property string $subscribeurl
 * @property string $jsapi_ticket
 * @property string $card_ticket
 */
class WechatAccounts extends \yii\db\ActiveRecord
{



    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '微信公众号',      //用于修改了什么的显示
        'mainfield' => 'name',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];


    const WID = 1;



    /**
     * 未激活状态
     */
    const STATUS_INACTIVE = 0;
    /**
     * 激活状态
     */
    const STATUS_ACTIVE = 1;
    /**
     * 删除状态
     */
    const STATUS_DELETED = -1;
    /**
     * 普通订阅号
     */
    const TYPE_SUBSCRIBE = 0;
    /**
     * 认证订阅号
     */
    const TYPE_SUBSCRIBE_VERIFY = 1;
    /**
     * 普通服务号
     */
    const TYPE_SERVICE = 2;
    /**
     * 认证服务号
     */
    const TYPE_SERVICE_VERIFY = 3;
    /**
     * 公众号类型列表
     * @var array
     */
    public static $types = [
        self::TYPE_SUBSCRIBE => '订阅号',
        self::TYPE_SUBSCRIBE_VERIFY => '认证订阅号',
        self::TYPE_SERVICE_VERIFY => '认证服务号',
        self::TYPE_SERVICE => '普通服务号'
    ];
    public static $statuses = [
        self::STATUS_INACTIVE => '未接入',
        self::STATUS_ACTIVE => '已接入',
        self::STATUS_DELETED => '已删除'
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%wechat_accounts}}';
    }


    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['token', 'name', 'account', 'original', 'signature', 'key', 'secret', 'encodingaeskey', 'subscribeurl','encodingaeskey'], 'required'],
            [['id', 'level', 'lastupdate', 'styleid'], 'integer'],
            [['token', 'password'], 'string', 'max' => 32],
            [['access_token', 'jsapi_ticket', 'card_ticket'], 'string', 'max' => 1000],
            [['name', 'account', 'username'], 'string', 'max' => 30],
            [['original', 'key', 'secret'], 'string', 'max' => 50],
            [['signature'], 'string', 'max' => 100],
            [['country'], 'string', 'max' => 10],
            [['province'], 'string', 'max' => 3],
            [['city'], 'string', 'max' => 15],
            [['encodingaeskey'], 'string', 'max' => 255],
            [['subscribeurl'], 'string', 'max' => 120],
            [['id','country', 'province', 'city','username', 'password','jsapi_ticket', 'card_ticket'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'token' => 'Token',
            'access_token' => 'Access Token',
            'level' => '公众号类别',
            'name' => '公共号名称',
            'account' => '账号',
            'original' => '原始id',
            'signature' => '公众号描述',
            'lastupdate' => '上次更新时间',
            'key' => 'appid',
            'secret' => 'appSecret',
            'encodingaeskey' => 'Encodingaeskey',
            'subscribeurl' => '引导关注地址',
        ];
    }
}
